<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="125px"
    >
      <el-form-item label="姓名" prop="param">
        <el-input
          v-model="queryParams.param"
          placeholder="请输入姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="省" prop="province">
        <el-input
          v-model="queryParams.province"
          placeholder="请输入省"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="市" prop="city">
        <el-input
          v-model="queryParams.city"
          placeholder="请输入市"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="区" prop="district">
        <el-input
          v-model="queryParams.district"
          placeholder="请输入区"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['course:realName:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['course:realName:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['course:realName:remove']"
          >删除</el-button
        >
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="realNameList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="姓名" align="center" prop="legalName" />
      <el-table-column label="预留手机号" align="center" prop="mobile" width="90px" />
      <el-table-column
        label="银行账户类型"
        align="center"
        prop="bankAccountType"
        width="100px"
      >
        <template slot-scope="scope">
          <span>{{ scope.row.bankAccountType === "0" ? "借记卡" : "对公账户" }}</span>
        </template>
      </el-table-column>
      <el-table-column label="账户姓名" align="center" prop="bankName" />
      <el-table-column label="银行卡号" align="center" prop="bankCardNo" />
      <!-- <el-table-column label="开户行" align="center" prop="bankCode"/> -->
      <el-table-column
        label="身份证号码"
        align="center"
        prop="legalLicenceNo"
        width="100px"
      />
      <!-- <el-table-column label="身份证正面" align="center" prop="legalLicenceFrontUrl" width="100px"/> -->
      <!-- <el-table-column label="身份证反面" align="center" prop="legalLicenceBackUrl" width="100px"/> -->
      <!-- <el-table-column label="法人证件有效期开始时间" align="center" prop="startDate" width="190px"/> -->
      <!-- <el-table-column label="法人证件有效期截止时间" align="center" prop="expired" width="190px"/> -->
      <!-- <el-table-column label="法人证件居住地址" align="center" prop="legalAddress" width="160px"/> -->
      <el-table-column label="企业类型" align="center" prop="signType">
        <template slot-scope="scope">
          <span>{{ scope.row.signType === "0" ? "个体工商户" : "企业" }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="统一社会信息代码"
        align="center"
        prop="licenceNo"
        width="130px"
      />
      <!-- <el-table-column label="营业执照地址" align="center" prop="licenceUrl" width="120px"/> -->
      <el-table-column label="主体名称" align="center" prop="signName"  show-overflow-tooltip />
      <el-table-column label="企业简称" align="center" prop="shortName"  show-overflow-tooltip />
      <!-- <el-table-column label="开户许可证照片" align="center" prop="openAccountLicenceUrl" width="120px"/> -->
      <el-table-column
        label="联系人姓名"
        align="center"
        prop="contactName"
        width="100px"
      />
      <el-table-column
        label="联系人证件号码"
        align="center"
        prop="contactLicenceNo"
        width="120px"
      />
      <el-table-column
        label="联系人手机号"
        align="center"
        prop="contactMobile"
        width="110px"
      />
      <el-table-column
        label="联系人邮箱"
        align="center"
        prop="contactEmail"
        width="100px"
      />
      <el-table-column
        label="管理员邮箱"
        align="center"
        prop="adminEmail"
        width="110px"
      />
      <el-table-column
        label="管理员电话"
        align="center"
        prop="adminMobile"
        width="100px"
      />
      <el-table-column label="省" align="center" prop="province" />
      <el-table-column label="市" align="center" prop="city" />
      <el-table-column label="区" align="center" prop="district" />
      <!-- <el-table-column label="详细地址" align="center" prop="address" /> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['course:realName:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['course:realName:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改实名认证对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="170px">
        <el-form-item label="姓名" prop="legalName">
          <el-input v-model="form.legalName" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="预留手机号" prop="mobile">
          <el-input v-model="form.mobile" placeholder="请输入预留手机号" />
        </el-form-item>
        <el-form-item label="账户姓名" prop="bankName">
          <el-input v-model="form.bankName" placeholder="请输入账户姓名" />
        </el-form-item>
        <el-form-item label="银行卡号" prop="bankCardNo">
          <el-input v-model="form.bankCardNo" placeholder="请输入银行卡号" />
        </el-form-item>
        <el-form-item label="开户行" prop="bankCode">
          <el-input v-model="form.bankCode" placeholder="请输入开户行" />
        </el-form-item>
        <el-form-item label="身份证号码" prop="legalLicenceNo">
          <el-input v-model="form.legalLicenceNo" placeholder="请输入身份证号码" />
        </el-form-item>
        <el-form-item label="身份证正面" prop="legalLicenceFrontUrl">
          <image-upload v-model="form.legalLicenceFrontUrl" :limit="1" />
        </el-form-item>
        <el-form-item label="身份证反面" prop="legalLicenceBackUrl">
          <image-upload v-model="form.legalLicenceBackUrl" :limit="1" />
        </el-form-item>
        <el-form-item label="法人证件有效期开始时间" prop="startDate">
          <el-input v-model="form.startDate" placeholder="请输入法人证件有效期开始时间" />
        </el-form-item>
        <el-form-item label="法人证件有效期截止时间" prop="expired">
          <el-input v-model="form.expired" placeholder="请输入法人证件有效期截止时间" />
        </el-form-item>
        <el-form-item label="法人证件居住地址" prop="legalAddress">
          <el-input v-model="form.legalAddress" placeholder="请输入法人证件居住地址" />
        </el-form-item>
        <el-form-item label="统一社会信息代码" prop="licenceNo">
          <el-input v-model="form.licenceNo" placeholder="请输入统一社会信息代码" />
        </el-form-item>
        <el-form-item label="营业执照地址" prop="licenceUrl">
          <el-input v-model="form.licenceUrl" placeholder="请输入身份证反面地址" />
        </el-form-item>
        <el-form-item label="主体名称" prop="signName">
          <el-input v-model="form.signName" placeholder="请输入主体名称" />
        </el-form-item>
        <el-form-item label="企业简称" prop="shortName">
          <el-input v-model="form.shortName" placeholder="请输入企业简称" />
        </el-form-item>
        <el-form-item label="开户许可证照片" prop="openAccountLicenceUrl">
          <image-upload v-model="form.openAccountLicenceUrl" :limit="1" />
        </el-form-item>
        <el-form-item label="联系人姓名" prop="contactName">
          <el-input v-model="form.contactName" placeholder="请输入联系人姓名" />
        </el-form-item>
        <el-form-item label="联系人证件号码" prop="contactLicenceNo">
          <el-input v-model="form.contactLicenceNo" placeholder="请输入联系人证件号码" />
        </el-form-item>
        <el-form-item label="联系人手机号" prop="contactMobile">
          <el-input v-model="form.contactMobile" placeholder="请输入联系人手机号" />
        </el-form-item>
        <el-form-item label="管理员邮箱" prop="adminEmail">
          <el-input v-model="form.adminEmail" placeholder="请输入管理员邮箱" />
        </el-form-item>
        <el-form-item label="管理员电话" prop="adminMobile">
          <el-input v-model="form.adminMobile" placeholder="请输入管理员电话" />
        </el-form-item>
        <el-form-item label="联系人邮箱" prop="contactEmail">
          <el-input v-model="form.contactEmail" placeholder="请输入联系人邮箱" />
        </el-form-item>
        <el-form-item label="省" prop="province">
          <el-input v-model="form.province" placeholder="请输入省" />
        </el-form-item>
        <el-form-item label="市" prop="city">
          <el-input v-model="form.city" placeholder="请输入市" />
        </el-form-item>
        <el-form-item label="区" prop="district">
          <el-input v-model="form.district" placeholder="请输入区" />
        </el-form-item>
        <el-form-item label="详细地址" prop="address">
          <el-input v-model="form.address" placeholder="请输入详细地址" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer" style="text-align: center">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listRealName,
  getRealName,
  delRealName,
  addRealName,
  updateRealName,
} from "@/api/course/realName";

export default {
  name: "RealName",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 实名认证表格数据
      realNameList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        legalName: null,
        province: null,
        city: null,
        district: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询实名认证列表 */
    getList() {
      this.loading = true;
      listRealName(this.queryParams).then((response) => {
        this.realNameList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        legalName: null,
        mobile: null,
        bankAccountType: null,
        bankName: null,
        bankCardNo: null,
        bankCode: null,
        legalLicenceNo: null,
        legalLicenceFrontUrl: null,
        legalLicenceBackUrl: null,
        startDate: null,
        expired: null,
        legalAddress: null,
        signType: null,
        licenceNo: null,
        licenceUrl: null,
        signName: null,
        shortName: null,
        openAccountLicenceUrl: null,
        contactName: null,
        contactLicenceNo: null,
        contactMobile: null,
        contactEmail: null,
        province: null,
        city: null,
        district: null,
        address: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        delFlag: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加实名认证";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getRealName(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改实名认证";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        console.log("[ form ] >", this.form);
        if (valid) {
          if (this.form.id != null) {
            updateRealName(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addRealName(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除实名认证编号为"' + ids + '"的数据项？')
        .then(function () {
          return delRealName(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "course/realName/export",
        {
          ...this.queryParams,
        },
        `realName_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
